package vn.edu.hut.soict.translate.wordgraph;

public class DefaultWord implements Word {
	private String text;
	private String partOfSpeech;

	public DefaultWord(String text, String partOfSpeechs) {
		this.text = text;
		this.partOfSpeech = partOfSpeechs;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getPartOfSpeech() {
		return partOfSpeech;
	}

	public void setPartOfSpeech(String partOfSpeech) {
		this.partOfSpeech = partOfSpeech;
	}

	@Override
	public String partOfSpeech() {
		return partOfSpeech;
	}

	public boolean isContentWord() {
		char type = partOfSpeech.charAt(0);
		if (type == 'A' || type == 'N' || type == 'P' || type == 'V' || type == 'I') {
			return true;
		}
		return false;
	}

	public boolean samePartOfSpeech(Word w) {
		if (!(w instanceof DefaultWord)) {
			return false;
		}
		DefaultWord word = (DefaultWord) w;
		return partOfSpeech.equals(word.partOfSpeech);
	}

	public boolean isIdentical(Word w) {
		if (w == null) {
			return false;
		}
		if (!(w instanceof DefaultWord)) {
			return false;
		}
		DefaultWord word = (DefaultWord) w;
		if (!text.equalsIgnoreCase(word.text)) {
			return false;
		}
		if (!partOfSpeech.equals(word.partOfSpeech)) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		DefaultWord other = (DefaultWord) obj;
		if (!text.equalsIgnoreCase(other.text)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return text + "|" + partOfSpeech;
	}
}